
package com.arcsoft.crud.limitTime.task;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

import com.arcsoft.crud.Constants.Global;
import com.arcsoft.crud.limitTime.base.BenchmarkTimeTask;
import com.arcsoft.crud.util.ConnectionDB;
import com.arcsoft.log.entity.OptimizeAnalyzeLog;

public class SelectSigleTimeTask extends BenchmarkTimeTask{

	public SelectSigleTimeTask(int threadIndex, CountDownLatch parent, int printInfoInterval,
			String taskLogTable) {
		super(threadIndex, parent, printInfoInterval, taskLogTable);
	}
	
	@Override
	public String execute(){
		ConnectionDB db = new ConnectionDB();
		
		Map<String, Long> map = prepareData();
		
        String sql = "select * from people where id = ?";
  
        long startId =map.get("startId");
        long scope = map.get("scope");
        long param =(long)(Math.random()*(map.get("endId")-map.get("startId")))+startId;
        Object arrays[] = {param};
        
        db.getDataBySql(sql, arrays);
        return parseSql(sql, arrays);
	}
	
	@Override
	public void logInfo(Date startTime, Date endTime, String requestDetail, int extendTime){
		String sceneDesc = Global.OPERATOR_TYPE_SELECT_SINGLE+"-"+Global.THREAD_COUNT+"C-"+Global.WARMTIME+"W-"+Global.EXECUTE_TIME+"E";//场景名命名规则 操作类型-并发数C-预热时间W-执行时间E
		
		OptimizeAnalyzeLog optimizeAnalyzeLog = new OptimizeAnalyzeLog
					(sceneDesc,Global.OPERATOR_TYPE_SELECT_SINGLE,startTime, endTime, extendTime, requestDetail);
		
		insertLog(optimizeAnalyzeLog);
	}
}
